package com.exercise.family

import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.fun.utils.RString
import com.fun.utils.Time

class PubData extends FunBase {

    static String content = "/pubdata"

    static PubData drive = new PubData()

    public JSONObject add() {
        String url = content + "/edit"
        def params = new JSONObject()
        params.put("envId", getRandomInt(3))
        params.put("uid", 1079)
        params.put("name", RString.getString(10))
        params.put("type", "add")
        def response = getPostResponse(url, params)
        output(response)
    }

    public JSONObject getAllDatas() {
        String url = content + "/get"
        def params = new JSONObject()
        params.put("uid", 763)
        params.put("envId", 2)
        def response = getGetResponse(url,params)
        output(response)
    }

    public JSONObject updateAttr() {
        String url = content + "/edit"
        def params = new JSONObject()
        params.put("id", 1111)
        params.put("uid", 763)
        params.put("name", Time.getDate())
        params.put("type", "update")
        def response = getPostResponse(url, params)
        output(response)
    }

    public JSONObject del() {
        String url = content + "/edit"
        def params = new JSONObject()
        params.put("id", 1091)
        params.put("uid", 105)
        params.put("type", "delete")
        def response = getPostResponse(url, params)
        output(response)
    }


    public JSONObject save() {
        String url = content + "/save"
        def params = new JSONObject()
        params.put("id", 1111)
        params.put("uid", 763)
        JSONArray list = new JSONArray()
        def detail = new JSONObject()
        detail.put("text", "FunTester" + RString.getString(5))
        detail.put("value", "uid=102")
        list << detail
        list << detail.clone()
        list << detail.clone()
        list << detail.clone()
        params.put("list", list)
        def response = getPostResponse(url, params)
        output(response)
    }

    public static void main(String[] args) {
//        drive.add()
//        drive.add()
//        drive.add()
//        drive.add()
//        drive.add()
//        drive.updateAttr()
//        drive.del()
        drive.save()
//        drive.getAllDatas()
        testOver()
    }
}
